package icu.honeysuccess.gateway.text;

import io.jsonwebtoken.*;
import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties;

import java.util.Date;
import java.util.UUID;

/**
 * @author Honey
 * @date 2022/3/19
 */
public class JwtTest {

    private static Long time = 1000 * 60 * 60 * 24L;
    private static String signature = "admin";


    public static void main(String[] args) {
        JwtBuilder jwtBuilder = Jwts.builder()
                // Header
                .setHeaderParam("typ","JWT")
                .setHeaderParam("alg","HS256")
                // payload
                .claim("username","honeysuccess")
                .claim("role","admin")
                .setSubject("test")
                .setExpiration(new Date(System.currentTimeMillis() + time))
                .setId(UUID.randomUUID().toString())
                // signature
                .signWith(SignatureAlgorithm.HS256,signature);
        String token = jwtBuilder.compact();
        System.out.println(token);

        JwtParser parser = Jwts.parser();
        Jws<Claims> claimsJws = parser.setSigningKey("admi").parseClaimsJws(token);
        Claims body = claimsJws.getBody();
        System.out.println(body);


    }

}
